import * as THREE from 'three';

export interface BasicItemInfo {
  /** 模型列表，用于3D页左侧展示的列表 */
  objs: Array<{
    obj: THREE.Object3D;
  }>;
}

export interface BasicSceneOptions<T = BasicItemInfo> {
  id: string;
  camera: THREE.Camera;
  scene: THREE.Scene;
  canvas: HTMLCanvasElement;
  ItemList: Record<string, T>;
  onCurrentSceneEnter?: Function;
  onCurrentSceneLeave?: Function;
}

export interface Default3DAxis {
  x: number;
  y: number;
  z: number;
}

export interface CameraInfo {
  P: Default3DAxis;
  R: Default3DAxis;
}

export default abstract class BasicScene {
  id: string;
  ItemList: Record<string, BasicItemInfo>;
  camera: THREE.Camera;
  scene: THREE.Scene;
  canvas: HTMLCanvasElement;
  onCurrentSceneEnter?: Function;
  onCurrentSceneLeave?: Function;

  constructor({ id, camera, scene, ItemList, canvas, onCurrentSceneLeave, onCurrentSceneEnter }: BasicSceneOptions) {
    this.id = id;
    this.ItemList = ItemList ?? {};
    this.camera = camera;
    this.scene = scene;
    this.canvas = canvas;
    this.onCurrentSceneLeave = onCurrentSceneLeave;
    this.onCurrentSceneEnter = onCurrentSceneEnter;

    for (const i in this.ItemList) {
      if (Object.prototype.hasOwnProperty.call(this.ItemList, i)) {
        this.scene.add(this.ItemList[i].objs[0].obj);
      }
    }
  }

  abstract onSceneChange(id: string, ...args: any): any;
  abstract animate(time: number): any;
}
